package com.sheep.springboot.config;

import com.sheep.springboot.filter.MyFilter;
import com.sheep.springboot.servlet.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类
 * author: sheep.Old
 * qq: 64341393
 * Created 2018/11/2
 */
@Configuration // 标识该类为一个配置类， 相当于在application.xml文件
public class CustomConfig {

    /**
     * @Bean 注解相当于xml文件中的bean节点配置
     *  <bean id="myServletRegistrationBean" class="org.springframework.boot.web.servlet.ServletRegistrationBean"></bean>
     * @retur
     */
    @Bean
    public ServletRegistrationBean myServletRegistrationBean(){
        ServletRegistrationBean<MyServlet> bean = new ServletRegistrationBean<>(new MyServlet(), "/myServlet");
        return bean;
    }


    /**
     * 配置过滤器
     * @return
     */
    @Bean
    public FilterRegistrationBean myFilterRegistrationBean(){
        FilterRegistrationBean<MyFilter> registrationBean = new FilterRegistrationBean<>(new MyFilter());
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }

}
